package com.xch.sboot.config.login;

import com.xch.sboot.persistence.domain.account.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * @author xch
 * 2022/12/14 15:09
 */
@Data
@NoArgsConstructor
@ApiModel(description = "Session")
public class Session {
    @ApiModelProperty("token")
    private String token;

    @ApiModelProperty("用户名")
    private String username;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty("昵称")
    private String nickname;

    @ApiModelProperty("登录时间")
    private LocalDateTime signinTime;

    public Session(@NotNull User user, @NotEmpty String token) {
        BeanUtils.copyProperties(user, this);
        signinTime = LocalDateTime.now();
        this.token = token;
    }

    @Override
    public String toString() {
        return "Session{" +
                "token='" + token + '\'' +
                ", username='" + username + '\'' +
                ", email='" + email + '\'' +
                ", nickname='" + nickname + '\'' +
                ", signinTime=" + signinTime +
                '}';
    }
}
